define(['text!sys/menu/menu.html'], function (Template) {
    var component = {
        template: Template,
        data: function () {
            return {
                pageDataMenu: [],
                queryName: '',
                show: false,
                entity: {},
                addUp: 0,//0为修改，1为添加
                rank:1,//菜单级别
                fatherTypeId:0,


            }
        },
        methods: {
            searchSubset:function (entity) {
                var _this = this;
                _this.fatherTypeId = entity.id;
                _this.rank = Number(entity.menuGrade)+1;
                $.post("/home/menu/selectStair",
                    {"param": Number(_this.pageDataMenu[0].menuGrade)+1,"fatherTypeId":entity.id},
                    function (data) {
                        _this.pageDataMenu = data.data.page;

                    });
            },
            
            searchData: function () {
                var _this = this;
                if(_this.addUp == 0){
                    $.post("/home/menu/updateEntity",
                        {"entity": JSON.stringify(_this.entity)},
                        function (data) {
                            if (data.code == 200) {
                                _this.show = false;
                                _this.$message({
                                    type: 'success',
                                    message: '操作成功!'
                                });
                            } else {
                                _this.$message({
                                    type: 'error',
                                    message: '操作失败!'
                                });
                            }
                        });
                }else{
                    debugger
                    _this.entity.menuGrade = _this.rank;
                    _this.entity.fatherTypeId = _this.fatherTypeId;
                    $.post("/home/menu/insertEntity",
                        {"entity": JSON.stringify(_this.entity)},
                        function (data) {
                            if (data.code == 200) {
                                _this.show = false;
                                _this.$message({
                                    type: 'success',
                                    message: '操作成功!'
                                });
                            } else {
                                _this.$message({
                                    type: 'error',
                                    message: '操作失败!'
                                });
                            }
                        });
                }
            },
            toAdd: function () {
                var _this = this;
                _this.entity = {};
                _this.show = true;
                _this.addUp = 1;


            },
            toEdit: function (entity) {
                var _this = this;
                _this.show = true;
                _this.entity = entity;
                _this.addUp = 0;
            },
            del: function (entity) {
                var _this = this;
                _this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'error'
                }).then(function () {
                    $.post("/home/menu/deleteEntity",
                        {"entityId":entity.id},
                        function (data) {
                            if (data.code == 200) {
                                _this.show = false;
                                _this.$message({
                                    type: 'success',
                                    message: '操作成功!'
                                });
                            } else {
                                _this.$message({
                                    type: 'error',
                                    message: '操作失败!'
                                });
                            }
                        });
                }).catch(function () {
                });
            },
            //修改添加数据信息
        },
        created: function () {
            var _this = this;
            $.post("/home/menu/selectStair",
                {"param": 1,"fatherTypeId":0},
                function (data) {
                    _this.pageDataMenu = data.data.page;
                    _this.addUp= 0;//0为修改，1为添加


                });
        }
    };

    // 定义子路由
    // var subRoute = [{
    //     path: 'edit/:entity',
    //     component: function (resolve) {
    //         require(['sys/org/org-edit'], function (o) {
    //             resolve(o)
    //         });
    //     }
    // }];

    return {
        component: component         //返回组件
        // subRoute:subRoute        //返回子路由
    }

});